<?php
class DealOrderDSBase extends AbstractDSBase {
	/**	 * The DealOrderEntity Object will be created before calling create function	 *	 * @access public	 *	 * @return DealOrderEntity object	 *	 */
	public function beforeCreate() {
		// New DealOrderEntity		$dealOrderEntity = new DealOrderEntity ();
		$dealOrderEntity = parent::beforeInsert ( $dealOrderEntity );
		
		// Return DealOrderEntity		return $dealOrderEntity;
	}
	
	/**	 * The DealOrderEntity Object will be getted item from database before calling update function	 *	 * @access public	 *	 * @param int $id: Id of the deal	 *	 * @return DealOrderEntity object	 *	 */
	public function beforeUpdate($id) {
		// Get deal item		$dealOrderEntity = $this->getById ( $id );
		
		// Return DealOrderEntity		return $dealOrderEntity;
	}
	
	/**	 * Insert new row to service	 *	 * @access public	 *	 * @param DealOrderEntity $dealOrderEntity: object to be inserted	 *	 * @return array of primary key of new inserted row	 */
	public function create($dealOrderEntity) {
		// New Data Access of service		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Create service and return		return $dealOrderDataAccess->create ( $dealOrderEntity );
	}
	
	/**	 * Update an existing row of deal	 *	 * @access public	 *	 * @param DealOrderEntity $dealOrderEntity: object to be updated	 *	 * @return bool	 */
	public function update($dealOrderEntity) {
		// New Data Access of deal		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Update service item and return		return $dealOrderDataAccess->update ( $dealOrderEntity );
	}
	
	/**	 * Delete an existing row of deal	 *	 * @access public	 *	 * @param int $id: id of row need to be deleted	 *	 * @return bool	 */
	public function del($id) {
		// New Data Access of deal		$dealOrderDataAccess = new DealOrderDataAccess ();
		$result = false;
		if (! is_null ( $id )) {
			
			// Detele deal and return			$result = $dealOrderDataAccess->del ( $id );
		}
		
		return $result;
	}
	
	/**	 * Get deal item	 *	 * @access public	 *	 * @param int $id: Id of deal	 *	 * @return DealOrderEntity object	 */
	public function getById($id) {
		// New Data Access of deal		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get deal item and return		return $dealOrderDataAccess->getById ( $id );
	}
	
	/**	 * Get all rows of deal table with search criterias	 *	 * @access public	 *	 * @param array $arrElement: array of search criterias	 * @param string $orderby: Field and the way ordered (ASC or DESC)	 * @param int $begin: Begin item	 * @param int $limit: Number rows to query	 *	 * @return array DealOrderEntity object	 */
	public function getItems($arrElement, $orderby = null, $begin = null, $limit = null) {
		// New Data Access of service		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get all deal based on search criterias		return $dealOrderDataAccess->getItems ( $arrElement, $orderby, $begin, $limit );
	}
	
	public function getItemsAll($arrElement, $orderby = null, $begin = null, $limit = null,$where = null) {
		// New Data Access of service
		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get all deal based on search criterias
		return $dealOrderDataAccess->getItemsAll ( $arrElement, $orderby, $begin, $limit, $where );
	}
	public function getAllItems($arrElement, $orderby = null, $begin = null, $limit = null,$where = null) {
		// New Data Access of service
		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get all deal based on search criterias
		return $dealOrderDataAccess->getAllItems ( $arrElement, $orderby, $begin, $limit, $where );
	}
	public function getOrderOfDeal($deal_id = null) {
		// New Data Access of service
		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get all deal based on search criterias
		return $dealOrderDataAccess->getOrderOfDeal ($deal_id);
	}
	public function getOrdersOfUser($user_id) {
		// New Data Access of service		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get all deal based on search criterias		return $dealOrderDataAccess->getOrdersOfUser ( $user_id );
	}
	
	public function getOrder($order_id) {
		// New Data Access of service
		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get all deal based on search criterias
		return $dealOrderDataAccess->getOrder ( $order_id );
	}
	/**	 * Get total items of deal	 *	 * @access public	 *	 * @param array $arrElement: array of search criterias	 *	 * @return int total: Num of rows of deal	 */
	public function getTotals($arrElement) {
		// New Data Access of deal		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get total items of deal based on search criterias and return		return $dealOrderDataAccess->getTotals ( $arrElement );
	}
	public function DealOrderStatistics($dateTo, $dateEnd){
		// New Data Access of deal
		$dealOrderDataAccess = new DealOrderDataAccess ();
		
		// Get total items of deal based on search criterias and return
		return $dealOrderDataAccess->DealOrderStatistics ($dateTo, $dateEnd);
	
	}
	public function CategoryOrderStatistics($dateTo, $dateEnd){
		$dealOrderDataAccess = new DealOrderDataAccess();
		return $dealOrderDataAccess->CategoryOrderStatistics($dateTo, $dateEnd);
	}
	public function SalesStatistics($dateTo, $dateEnd){
		$dealOrderDataAccess = new DealOrderDataAccess();
		return $dealOrderDataAccess->SalesStatistics($dateTo, $dateEnd);
	}
	public function getShippingOfStaff($param = array()){
		$dealOrderDataAccess = new DealOrderDataAccess();
		return $dealOrderDataAccess->getShippingOfStaff($param);
	}
}